<?php
allowCors();
if(!methodsRequired(["post"])) return;

if (isset($_REQUEST["user_name"]) && isset($_REQUEST["password"])) {
    $username = $_REQUEST["user_name"];
    $password = $_REQUEST["password"];
    $admin = new Admin();
    if ($db->query($admin, ["name"=>"admin_name","value"=>$username]) && $admin->confirm($password)) {
        $msg->setCode(0);
        session_start();
        $_SESSION["admin"] = $admin->getAdminId();
    } else {
        $msg->setCode(-1);
    }
} else {
    $msg->setCode(-1);
}

echo $msg;
